package com.sinven.serivce;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sinven.common.Pager;
import com.sinven.mapper.ContentMapper;
import com.sinven.pojo.Content;
import com.sinven.pojo.Leave;

@Service
public class ContentSerivceImpl implements ContentSerivce{

	@Autowired
	private ContentMapper contentMapper;

	/**
 	 * 添加
	 */
	@Override
	public Boolean addContent(Content content) {
		//调用contentMapper中的addContent，返回一个int的result
		int row = contentMapper.addContent(content);
		//使用if判断如果row>0返回true否则返回false
		if(row>0) {
			return true;
		}
		return false;
	}

	@Override
	public Boolean deleteContent(Long tid) {
		//调用contentMapper中的deleteContent，返回一个int的result
		int row = contentMapper.deleteContent(tid);
		//使用if判断如果row>0返回true否则返回false
		if(row>0) {
			return true;
		}
		return false;
	}

	@Override
	public Boolean updateContent(Content content) {
		//调用contentMapper中的updateContent，返回一个int的result
		int row = contentMapper.updateContent(content);
		//使用if判断如果row>0返回true否则返回false
		if(row>0) {
			return true;
		}
		return false;
	}

	@Override
	public List<Content> tcreationtimeDescending(Long cid,Integer roof) {
		return contentMapper.tcreationtimeDescending(cid,roof);
	}

	
	
	
	@Override
	public Pager<List<Content>> queryPaging(Long startIndex, Integer pageSize, Long cid,Long uid) {
		// TODO Auto-generated method stub
		// 得到总记录数
		 long totalRecords = contentMapper.countContent(cid,uid);
		 if (totalRecords == 0) {
				return null;
			}
		 Pager<List<Content>> pager = 
				 new Pager<>(totalRecords, startIndex, pageSize);
		 List<Content> contentlist = contentMapper.queryPaging(pager.getStartIndex(), pager.getPageSize(), cid,uid);
		 pager.setData(contentlist);
		 return pager;
	}

	@Override
	public Long countContent(Long cid,Long uid) {
		return contentMapper.countContent(cid,uid);
	}

	@Override
	public Content queryBytid(Long tid) {
		return contentMapper.queryBytid(tid);
	}

	@Override
	public Boolean queryByroof(Long cid) {
		
		int rows=contentMapper.queryByroof(cid);
		System.out.println(rows);
		return rows>0?true:false;
	}
}
